package camera.OpenGl;

import android.content.Context;
import android.opengl.GLES20;

import camera.OpenGl.utils.ShaderLoader;
import openGl.utils.TextResourceReader;

/**
 * Created by Administrator on 2017/12/28.
 */

public class ShaderProgram {
    // Uniform 类型的常量
    protected static final String U_MATRIX = "u_Matrix";
    protected static final String U_TEXTURE_UNIT = "u_TextureUnit";

    // Attribute 类型的常量
    protected static final String A_POSITION = "a_Position";
    protected static final String A_COLOR = "a_Color";
    protected static final String A_TEXTURE_COORDINATES = "a_TextureCoordinates";

    // Shader program
    protected  int program;

    /**
     * 
     * @param context 上下文
     * @param vertexShaderResourceId 顶点着色器的代码文件资源
      * @param fragmentShaderResourceId 片元着色器的代码文件资源
     */
    public ShaderProgram(Context context,int vertexShaderResourceId,
                         int fragmentShaderResourceId) {

         program = ShaderLoader.buildProgram(
                TextResourceReader.readTextFileFromResource(context, vertexShaderResourceId),
                TextResourceReader.readTextFileFromResource(context, fragmentShaderResourceId));
    }

    /**
     * 使用OpenGl程序
     */
    public void useProgram(){
        GLES20.glUseProgram(program);
    }
    
}
